package com.study.sxc.Dao;

import com.study.sxc.Entity.Machine;
import com.study.sxc.Entity.LabSummary;
import com.study.sxc.Entity.StaffFeeSummary;
import org.apache.ibatis.annotations.*;
import java.util.Date;
import java.util.List;

@Mapper
public interface IMachineDao {
    @Select({
        "<script>",
        "SELECT machine_id AS machineId, lab_id AS labId, type_id AS typeId, status",
        "FROM Machines",
        "WHERE machine_id IN",
        "<foreach collection='list' item='id' open='(' separator=',' close=')'>",
        "#{id}",
        "</foreach>",
        "</script>"
    })
    List<Machine> getMachines(List<Integer> ids);

    @Insert("INSERT INTO Machines (lab_id, type_id, status) SELECT #{labId}, #{typeId}, #{status} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM Machines WHERE lab_id = #{labId} AND type_id = #{typeId})")
    @Options(useGeneratedKeys = true, keyProperty = "machineId")
    int addMachine(Machine machine);

    @Update("UPDATE Machines SET lab_id = #{labId}, type_id = #{typeId}, status = #{status} WHERE machine_id = #{machineId}")
    int updateMachine(Machine machine);

    @Delete("DELETE FROM Machines WHERE machine_id = #{id}")
    int deleteMachine(Integer id);

    @Select("SELECT machine_id AS machineId, lab_id AS labId, type_id AS typeId, status FROM Machines WHERE machine_id = #{id}")
    Machine getMachineById(Integer id);

    @Select("SELECT machine_id AS machineId, lab_id AS labId, type_id AS typeId, status FROM Machines")
    List<Machine> getAllMachines();

    @Select("CALL sp_lab_usage_summary()")
    List<LabSummary> getLabUsageSummary();

    @Select("CALL sp_staff_fees_summary(#{date1}, #{date2})")
    List<StaffFeeSummary> getStaffFeesSummary(@Param("date1") Date date1, @Param("date2") Date date2);
} 